package ControlComponents;

/**
 * This class simulates all the control flow instructions  (branching)
 * 
 * 
 *
 */
public class ControlInstructions {

	private ProgramCounter pc = null;
	private StatusRegister sr = null;
	
	/**
	 * Constructor to store program counter and status register
	 * @param pc program counter
	 * @param sr status register
	 */
	public ControlInstructions( ProgramCounter pc, StatusRegister sr ){
		this.pc = pc;
		this.sr =  sr;
	}

	/**
	 * Branch if status register zero bit is set. Program counter is loaded with general purpose register
	 * r7's content
	 *  @param address new value for program counter (general purpose register r7's content)
	 */
	public void BRZ( int address[] ){ 
		if( sr.getZero() == 1 ) {
			pc.set(address); 	
		}
	}


	/**
	 * Branch if status register carry bit is set. Program counter is loaded with general purpose register
	 * r7's content
	 *  @param address new value for program counter (general purpose register r7's content)
	 */
	public void BRC( int address[] ){ 
		if( sr.getCarry() == 1 ) 
			pc.set(address); 	
	}

	/**
	 *  Branch if status register negative bit is set. Program counter is loaded with general purpose register
	 * r7's content
	 * @param address new value for program counter (general purpose register r7's content)
	 */
	public void BRN( int address[] ){ 
		if( sr.getNegative() == 1 ) 
			pc.set(address); 	
	}

	/**
	 *  Branch if status register overflow bit is set. Program counter is loaded with general purpose register
	 * r7's content
	 * @param address new value for program counter (general purpose register r7's content)
	 */
	public void BRO( int address[] ){ 
		if( sr.getOverflow() == 1 ) 
			pc.set(address); 	
	}
}
